//
//  DetailScorll.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/5/22.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "DetailScorll.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@implementation DetailScorll

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSub];
    }
    return self;
}

- (void)createSub
{
    UIImage *image = [UIImage imageNamed:@"detailthree.jpg"];
    UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH , (SCREEN_WIDTH - 30)* 0.9)];
    myImageView.backgroundColor = [UIColor yellowColor];
    myImageView.image = image;
    myImageView.userInteractionEnabled = YES;
    [self addSubview:myImageView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, myImageView.frame.origin.y + myImageView.frame.size.height + 10, SCREEN_WIDTH - 30, myImageView.frame.size.height / 9)];
    titleLabel.text = @"智力黑提";
    //        titleLabel.backgroundColor = [UIColor yellowColor];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:titleLabel];
    
    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.frame.origin.x, titleLabel.frame.origin.y + titleLabel.frame.size.height, SCREEN_WIDTH - 30, titleLabel.frame.size.height - 8)];
    detailLabel.text = @"进口黑加仑提子葡萄新鲜水果";
    //        detailLabel.backgroundColor = [UIColor redColor];
    detailLabel.textColor = [UIColor colorWithRed:110.0/255.0 green:78.0/255.0 blue:71.0/255.0 alpha:1];
    detailLabel.font = [UIFont systemFontOfSize:15];
    [self addSubview:detailLabel];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(detailLabel.frame.origin.x, detailLabel.frame.origin.y + detailLabel.frame.size.height + 20,  SCREEN_WIDTH/2,2 * detailLabel.frame.size.height);
    [button setTitleColor:[UIColor colorWithRed:242.0 / 255.0 green:204.0 / 255.0 blue:49.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    button.layer.cornerRadius = CGRectGetHeight([button bounds])/2;
    button.backgroundColor = [UIColor colorWithRed:110.0/255.0 green:78.0/255.0 blue:71.0/255.0 alpha:1];
    [self addSubview:button];
    
    UIButton *carButton = [UIButton buttonWithType:UIButtonTypeCustom];
    carButton.frame = CGRectMake(button.frame.size.width - button.frame.size.height, 0, button.frame.size.height, button.frame.size.height);
    carButton.layer.cornerRadius = CGRectGetHeight([carButton bounds])/2;
    [carButton setImage:[UIImage imageNamed:@"shouyecar.png"] forState:UIControlStateNormal];
    [carButton.layer setBorderWidth:1.0];
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 255/255.0, 206/255.0, 0/255.0, 1});
    [carButton.layer setBorderColor:colorref];
    [carButton addTarget:self action:@selector(carButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [button addSubview:carButton];
    
    UILabel *shapeLabel = [[UILabel alloc] initWithFrame:CGRectMake(carButton.frame.size.width/3, carButton.frame.size.height/3, carButton.frame.size.height/2, carButton.frame.size.height/2)];
    shapeLabel.text = @"￥";
    shapeLabel.textAlignment = NSTextAlignmentRight;
//        shapeLabel.backgroundColor = [UIColor redColor];
    shapeLabel.textColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
    shapeLabel.font= [UIFont systemFontOfSize:17];
    [button addSubview:shapeLabel];
    
    UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(shapeLabel.frame.origin.x + shapeLabel.frame.size.width, 0, carButton.frame.size.width , carButton.frame.size.height)];
    priceLabel.text = @"1.00";
    priceLabel.textAlignment = NSTextAlignmentCenter;
//        priceLabel.backgroundColor = [UIColor greenColor];
    priceLabel.textColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
    priceLabel.font = [UIFont systemFontOfSize:20];
    [button addSubview:priceLabel];
    
    
    UILabel *countLable = [[UILabel alloc] initWithFrame:CGRectMake(priceLabel.frame.origin.x + priceLabel.frame.size.width, shapeLabel.frame.origin.y, shapeLabel.frame.size.width * 2, shapeLabel.frame.size.height)];
    countLable.text = @"/1个";
//        countLable.backgroundColor = [UIColor redColor];
    countLable.textAlignment = NSTextAlignmentLeft;
    countLable.textColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
    countLable.font = [UIFont systemFontOfSize:17];
    [button addSubview:countLable];
    
    UIImageView *detailImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, button.frame.origin.y + button.frame.size.height + 30, SCREEN_WIDTH, SCREEN_WIDTH)];
    //    detailImageView.contentMode = UIViewContentModeScaleAspectFit;
    UIImage *detailImage = [UIImage imageNamed:@"detailthree.jpg"];
    detailImageView.image = detailImage;
    [self addSubview:detailImageView];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, detailImageView.frame.origin.y + detailImageView.frame.size.height, SCREEN_WIDTH, SCREEN_WIDTH)];
    UIImage *imageV = [UIImage imageNamed:@"detailtwo.jpg"];
    imageView.image = imageV;
    [self addSubview:imageView];
    
    
    self.contentSize = CGSizeMake(SCREEN_WIDTH, myImageView.frame.size.height + titleLabel.frame.size.height + detailLabel.frame.size.height + button.frame.size.height + detailImageView.frame.size.height + imageView.frame.size.height + 200);
    
    
    
}

- (void)carButtonAction
{
    [self.carButtonDelegate carButtonAction];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
